R study

문기범

2020.02.04

Week 3

The future is here, it’s just not evenly distributed yet.

- William Gibson

R vs SPSS

링크

심리검사 결과지

웹사이트

Article

Animated plot

Data literacy with R

  • 수집 (import)
  • 정리 (tidy)
  • 변형 (transform)

==> 분석 (analysis, modeling)

Goals

  • 수집 / 정리 / 변형 / 분석

  • tidy data set

  • 기초 통계 / t검정 / 회귀 분석 / 다층 모형 Powered by R

  • 분석 결과 보고 (ggplot2, Rmarkdown)

Data literacy

  • 예시 데이터
## # A tibble: 852 x 4
##    학교  지역   성적 월소득
##    <chr> <chr> <dbl>  <dbl>
##  1 A대학 서울   90.3  100. 
##  2 A대학 서울   96.9  101. 
##  3 A대학 서울  106.   103. 
##  4 A대학 서울  112.   102. 
##  5 A대학 서울  115.   101. 
##  6 A대학 서울  119.    99.1
##  7 A대학 서울  124.    96.8
##  8 A대학 서울  128.    96.3
##  9 A대학 서울  135.    95.9
## 10 A대학 서울  140.    95.0
## # ... with 842 more rows

Data literacy

  • 산점도

Data literacy

  • 회귀선 추가

Data literacy

  • 단순 회귀 분석 결과
## # A tibble: 2 x 5
##   term        estimate std.error statistic   p.value
##   <chr>          <dbl>     <dbl>     <dbl>     <dbl>
## 1 (Intercept)  88.1       2.89       30.5  1.24e-138
## 2 월소득        0.0650    0.0431      1.51 1.31e-  1

Data literacy

  • 지역 구분

Data literacy

  • 상호작용 효과 분석
## # A tibble: 4 x 5
##   term            estimate std.error statistic   p.value
##   <chr>              <dbl>     <dbl>     <dbl>     <dbl>
## 1 (Intercept)      117.       3.81       30.8  1.83e-140
## 2 월소득            -0.396    0.0568     -6.98 5.85e- 12
## 3 지역서울         -58.2      5.38      -10.8  1.19e- 25
## 4 월소득:지역서울    0.922    0.0802     11.5  1.65e- 28

Data literacy

  • 학교 구분

Data literacy

  • 학교별 회귀분석
## # A tibble: 6 x 6
##   학교  term   estimate std.error statistic     p.value
##   <chr> <chr>     <dbl>     <dbl>     <dbl>       <dbl>
## 1 A대학 월소득    0.527    0.0964      5.47 0.000000202
## 2 B대학 월소득    0.526    0.0965      5.45 0.000000218
## 3 C대학 월소득    0.524    0.0967      5.42 0.000000253
## 4 D대학 월소득   -0.400    0.101      -3.97 0.000114   
## 5 E대학 월소득   -0.394    0.101      -3.89 0.000153   
## 6 F대학 월소득   -0.396    0.101      -3.92 0.000140

Data literacy

  • 기초 통계
## # A tibble: 6 x 5
##   학교  mean_월소득 mean_성적 sd_월소득 sd_성적
##   <chr>       <dbl>     <dbl>     <dbl>   <dbl>
## 1 A대학        63.2      92.3      22.7    28.5
## 2 B대학        63.2      92.2      22.7    28.5
## 3 C대학        63.2      92.3      22.7    28.5
## 4 D대학        63.2      92.2      22.7    28.5
## 5 E대학        63.2      92.3      22.6    28.5
## 6 F대학        63.2      92.3      22.7    28.5

Latte is horse.

라떼는 말이야

Tidyverse

Gapminder data:

  • 기대수명 ~ 1인당 GDP by 년도
  • tibble? data.frame?
## # A tibble: 1,704 x 6
##    country     continent  year lifeExp      pop gdpPercap
##    <fct>       <fct>     <int>   <dbl>    <int>     <dbl>
##  1 Afghanistan Asia       1952    28.8  8425333      779.
##  2 Afghanistan Asia       1957    30.3  9240934      821.
##  3 Afghanistan Asia       1962    32.0 10267083      853.
##  4 Afghanistan Asia       1967    34.0 11537966      836.
##  5 Afghanistan Asia       1972    36.1 13079460      740.
##  6 Afghanistan Asia       1977    38.4 14880372      786.
##  7 Afghanistan Asia       1982    39.9 12881816      978.
##  8 Afghanistan Asia       1987    40.8 13867957      852.
##  9 Afghanistan Asia       1992    41.7 16317921      649.
## 10 Afghanistan Asia       1997    41.8 22227415      635.
## # ... with 1,694 more rows

dplyr

https://rworkshop.uni.lu/lectures/lecture06_dplyr.html#55

group_by() %>% summarize()

https://statkclee.github.io/r-novice-gapminder/13-dplyr-kr.html

https://campus.datacamp.com/courses/exploratory-data-analysis-in-r-case-study/data-cleaning-and-summarizing-with-dplyr?ex=9

추천 사이트

인강 (첫 챕터 무료)

https://www.datacamp.com/courses/exploratory-data-analysis-in-r-case-study

백과사전

https://b-rodrigues.github.io/modern_R/index.html

신과 함께

https://www.google.com